﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Gem_Tools;
using Gem_Tools_Entity.Gem_Tools;
using Gem_Tools_Utility;
using Gem_Tools_Controller.Gem_Tools;

namespace GE_Management_Tool.Home_Page
{
    public partial class frm1004_Feedbacks_Edit_Form : frmBase
    {
        CAppointments m_objParent;
        CAppointments m_objAppointment;
        Boolean m_isNew = true;

        public frm1004_Feedbacks_Edit_Form()
        {
            InitializeComponent();
        }

        public CAppointments Show_To_Add(CAppointments p_objParent)
        {
            m_objParent = p_objParent;
            btnApprove.Enabled = false;
            this.ShowDialog();
            return m_objAppointment;
        }

        public CAppointments Show_To_Approve(CAppointments p_objFeedbacks)
        {
            m_isNew = false;
            m_objAppointment = p_objFeedbacks;
            btnSave.Enabled = false;
            Assign_Obj_To_Control();
            this.ShowDialog();

            return m_objAppointment;
        }

        private void Assign_Obj_To_Control()
        {
            btnChoose.EditValue = m_objAppointment.URL;
            txtDescription.Text = m_objAppointment.Description;
            dtmActualStart.DateTime = m_objAppointment.Actual_Start_Date;
            dtmActualEnd.DateTime = m_objAppointment.Actual_End_Date;
            dtmStart.DateTime = m_objAppointment.Start_Date;
        }

        private void Assign_Control_To_Obj()
        {
            m_objAppointment.Parent_ID = m_objParent.Auto_ID;
            m_objAppointment.is_Feedback = true;
            m_objAppointment.Subject = "Feedbacks: " + m_objParent.Subject;
            m_objAppointment.Start_Date = dtmStart.DateTime;
            m_objAppointment.End_Date = dtmStart.DateTime.AddHours(8);
            m_objAppointment.Actual_Start_Date = dtmStart.DateTime;
            m_objAppointment.Actual_End_Date = dtmStart.DateTime.AddHours(8);
            m_objAppointment.Resource_ID = m_objParent.Resource_ID;
            m_objAppointment.Percent_Complete = 0;
            m_objAppointment.Priority = 1;
            m_objAppointment.Label = m_objParent.Priority;
            m_objAppointment.Project_ID = m_objParent.Project_ID;
            m_objAppointment.Description = txtDescription.Text;
            m_objAppointment.Type = CUtility.Convert_To_Int32(EAppointments.Feedback);
            m_objAppointment.URL = btnChoose.Text;
        }

        private void buttonEdit1_Properties_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                if (folderBrowserDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    btnChoose.EditValue = folderBrowserDialog1.SelectedPath;
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                m_objAppointment = new CAppointments();
                Assign_Control_To_Obj();

                CAppointments_Controller v_CtrlAppointment = new CAppointments_Controller();
                v_CtrlAppointment.Insert_Appointments(m_objAppointment);

                XtraMessageBox.Show("Feedback Add Success !", "Warning", MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }

        private void btnApprove_Click(object sender, EventArgs e)
        {
            try
            {
                m_objAppointment.Percent_Complete = 100;
                m_objAppointment.Status = 4;
                CAppointments_Controller v_CtrlAppointment = new CAppointments_Controller();
                v_CtrlAppointment.Update_Appointments(m_objAppointment);

                XtraMessageBox.Show("Approved !", "Warning", MessageBoxButtons.OK);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK);
            }
        }


    }
}